from aiogram_dialog import DialogManager
from fluentogram import TranslatorRunner
from sqlalchemy.ext.asyncio import AsyncSession

from src.infrastructure.db.services.countries import query_countries


async def countries_getter(db_session: AsyncSession, dialog_manager: DialogManager, **kwargs):
    proxy_type: str = dialog_manager.dialog_data.get("proxy_type", "mobile")
    proxy_privacy: str = dialog_manager.dialog_data.get("proxy_privacy", "private")
    locale: TranslatorRunner = dialog_manager.middleware_data.get("locale")

    countries = await query_countries(db_session, proxy_type, proxy_privacy)

    return {
        "countries": countries,
        "count": len(countries),
        "user_language": locale.translators[0].locale,
    }
